package com.zjdiepu.www.manage.api.system;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.ibiz.system.IBaseRemitAccountService;
import com.zjdiepu.www.model.system.dto.BaseRemitAccount;
import com.zjdiepu.www.model.system.ext.BaseRemitAccountExt;

/**      
* 项目名称：dpqc-parent-manager-home   
* 类名称：RemitAccountController   
* 类描述：   
* 创建人：zhangzj
* 创建时间：2017年4月11日 下午3:46:49   
* 修改人：zhangzj
* 修改时间：2017年4月11日 下午3:46:49   
* 修改备注：   
* @version V1.0     
*/ 
@Controller
@RequestMapping("/RemitAccountController")
public class RemitAccountController extends BaseController{
	@Resource
	private IBaseRemitAccountService baseRemitAccountService;
	
	
	/** 
	* @author zhangzj
	* @Title: getRemitAccountPages 
	* @Description:查询所有数据
	* @param @param page
	* @param @param rows
	* @param @param remitAccount
	* @param @return    设定文件 
	* @return ApiResponse   返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/getRemitAccountPages")
	public ApiResponse getRemitAccountPages(@ModelAttribute BaseRemitAccountExt baseRemitAccountExt,String remitAccount){
		baseRemitAccountExt.notDeleted();
		baseRemitAccountExt.setAccounnNo(remitAccount);
        PageVo page = getPage(baseRemitAccountExt);
        int records = baseRemitAccountService.countByExt(baseRemitAccountExt);
        page.setRecords(records);
        if (records > 0) {
            List<BaseRemitAccount> baseRemitAccounts = baseRemitAccountService.selectByExt(baseRemitAccountExt);
            page.setRows(baseRemitAccounts);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
        return ApiResponse.success(page);
	}
	
	/** 
	* @author zhangzj
	* @Title: insert 
	* @Description: 新增一条记录
	* @param @param remitAccount
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/insert")
	public Map<String, Object> insert(BaseRemitAccount remitAccount){
		Map<String, Object> maps = super.success();
		try 
		{	AbstractSysUser currentUser = getCurrentUser();
			remitAccount.setModifier(currentUser.getId());
			remitAccount.setModifierName(currentUser.getName());
			baseRemitAccountService.saveUpdateAndDelete(remitAccount, OperateType.add);
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || insert");
		}
		return maps;
	}
	@ResponseBody
	@RequestMapping("/getById")
	public Map<String,Object> getById(String id){
		Map<String, Object> maps = super.success();
		try 
		{	
			Map<String, Object> aWhere = CollectionInitUtil.emptyMap();
			if(null != id && !("").equals(id))
			{
				aWhere.put("id", id);
			}
			BaseRemitAccount dpBaseRemitAccount=baseRemitAccountService.selectById(id);
			maps.put("result", dpBaseRemitAccount);
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || getById");
		}
		return maps;
	}
	
	/** 
	* @author zhangzj
	* @Title: update 
	* @Description: 修改
	* @param @param remitAccount
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/update")
	public Map<String,Object> update(BaseRemitAccount remitAccount){
		Map<String, Object> maps = super.success();
		try 
		{	AbstractSysUser currentUser = getCurrentUser();
			remitAccount.setModifier(currentUser.getId());
			remitAccount.setModifierName(currentUser.getName());
			baseRemitAccountService.saveUpdateAndDelete(remitAccount, OperateType.edit);
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || udpate");
		}
		return maps;
	}
	@ResponseBody
	@RequestMapping("/delete")
	public Map<String,Object> delete(String id){
		Map<String, Object> maps = super.success();
		try 
		{	AbstractSysUser currentUser = getCurrentUser();
			BaseRemitAccount remitAccount = new BaseRemitAccount();
			remitAccount.setModifier(currentUser.getId());
			remitAccount.setModifierName(currentUser.getName());
			baseRemitAccountService.saveUpdateAndDelete(remitAccount, OperateType.delete);
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || udpate");
		}
		return maps;
	}

}
